
package com.jf.cloud.delivery.controller.app;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.delivery.dto.TransfeeDTO;
import com.jf.cloud.delivery.model.Transfee;
import com.jf.cloud.delivery.service.TransfeeService;
import com.jf.cloud.delivery.vo.TransfeeVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 运费项
 *
 * @author zz
 * @date 2020-12-07 15:10:01
 */
@RestController("appTransfeeController")
@RequestMapping("/transfee")
@Tag(name = "运费项")
public class TransfeeController {

    @Autowired
    private TransfeeService transfeeService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取运费项列表" , description = "分页获取运费项列表")
    public ServerResponseEntity<PageVO<TransfeeVO>> page(@Valid PageDTO pageDTO) {
        PageVO<TransfeeVO> transfeePage = transfeeService.page(pageDTO);
        return ServerResponseEntity.success(transfeePage);
    }

    @GetMapping
    @Operation(summary = "获取运费项" , description = "根据transfeeId获取运费项")
    public ServerResponseEntity<TransfeeVO> getByTransfeeId(@RequestParam Long transfeeId) {
        return ServerResponseEntity.success(transfeeService.getByTransfeeId(transfeeId));
    }

    @PostMapping
    @Operation(summary = "保存运费项" , description = "保存运费项")
    public ServerResponseEntity<Void> save(@Valid @RequestBody TransfeeDTO transfeeDTO) {
        Transfee transfee = mapperFacade.map(transfeeDTO, Transfee.class);
        transfee.setTransfeeId(null);
        transfeeService.save(transfee);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新运费项" , description = "更新运费项")
    public ServerResponseEntity<Void> update(@Valid @RequestBody TransfeeDTO transfeeDTO) {
        Transfee transfee = mapperFacade.map(transfeeDTO, Transfee.class);
        transfeeService.update(transfee);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除运费项" , description = "根据运费项id删除运费项")
    public ServerResponseEntity<Void> delete(@RequestParam Long transfeeId) {
        transfeeService.deleteById(transfeeId);
        return ServerResponseEntity.success();
    }
}
